package com.muye.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.muye.dianli.R;
import com.muye.field.LinkageCommodityListData;

/**
 * 联动商品类型列表适配器
 * 
 * @author TangChao
 *
 */
public class LinkageCommodityListParentAdapter extends BaseAdapter
{
	private List<LinkageCommodityListData> arrayList;
	
	private Context context;
	
	public LinkageCommodityListParentAdapter(List<LinkageCommodityListData> arrayList, Context context)
	{
		super();
		this.arrayList = arrayList;
		this.context = context;
	}
	
	@Override
	public int getCount()
	{
		if (arrayList != null)
		{
			return arrayList.size();
		}
		return 0;
	}
	
	@Override
	public LinkageCommodityListData getItem(int position)
	{
		if (arrayList != null)
		{
			return arrayList.get(position);
		}
		return null;
	}
	
	@Override
	public long getItemId(int position)
	{
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		final ViewHolder viewHolder;
		if (convertView == null)
		{
			convertView = LayoutInflater.from(context).inflate(R.layout.linkage_commodity_list_adapter_layout, null);
			viewHolder = new ViewHolder();
			viewHolder.nameText = (TextView) convertView.findViewById(R.id.linkage_commidity_list_adapter_layout_text);
			convertView.setTag(viewHolder);
		}
		else
		{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if (viewHolder != null)
		{
			LinkageCommodityListData item = arrayList.get(position);
			viewHolder.nameText.setText(item.title);
		}
		return convertView;
	}
	
	private class ViewHolder
	{
		TextView nameText;
	}
}
